#include "stdafx.h"
#include "afxcontrolbarutil.h"
#include "UserDefineProperty.h"
#include "SpellDlg.h"
#include "ConfigListDlg.h"

#define AFX_PROP_HAS_LIST 0x0001
#define AFX_PROP_HAS_BUTTON 0x0002
#define AFX_PROP_HAS_SPIN 0x0004

/////////////////////////////////////////////////////////////////////////////
// CMFCPropertyGridFileProperty object

IMPLEMENT_DYNAMIC(CMFCPropertyUserDlgProperty, CMFCPropertyGridProperty)
CMFCPropertyUserDlgProperty::CMFCPropertyUserDlgProperty(const CString& strName, const CString& strFolderName, DWORD_PTR dwData, LPCTSTR lpszDescr, LPCTSTR lpszKey) 
: CMFCPropertyGridProperty(strName, COleVariant((LPCTSTR)strFolderName), lpszDescr, dwData)
{
	m_dwFlags = AFX_PROP_HAS_BUTTON;
	m_strKey = lpszKey;
}

CMFCPropertyUserDlgProperty::CMFCPropertyUserDlgProperty( const CString& strName, BOOL bOpenFileDialog, const CString& strFileName, LPCTSTR lpszDefExt, DWORD dwFileFlags, LPCTSTR lpszFilter, LPCTSTR lpszDescr, DWORD_PTR dwData) : CMFCPropertyGridProperty(strName, COleVariant((LPCTSTR)strFileName), lpszDescr, dwData)
{
	m_dwFlags = AFX_PROP_HAS_BUTTON;
}

CMFCPropertyUserDlgProperty::~CMFCPropertyUserDlgProperty()
{
}

void CMFCPropertyUserDlgProperty::SetDlgData(sEdit& edit)
{
	m_sdata = edit;
}

void CMFCPropertyUserDlgProperty::OnClickButton(CPoint /*point*/)
{
	ASSERT_VALID(this);
	ASSERT_VALID(m_pWndList);
	ASSERT_VALID(m_pWndInPlace);
	ASSERT(::IsWindow(m_pWndInPlace->GetSafeHwnd()));

	m_bButtonIsDown = TRUE;
	Redraw();

	switch (m_sdata.type)
	{
	case sEdit::E_spell_cast:
		{
			CSpellDlg oDlg;
			oDlg.InitData(m_sdata);
			oDlg.DoModal();
		}
		break;
	case sEdit::E_list:
		{
			CConfigListDlg oDlg;
			oDlg.InitData(m_sdata);
			oDlg.DoModal();
		}
		break;
	}
	m_bButtonIsDown = FALSE;
	Redraw();

	if (m_pWndInPlace != NULL)
	{
		m_pWndInPlace->SetFocus();
	}
	else
	{
		m_pWndList->SetFocus();
	}
}